package com.itheima.tliasmanagement.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class UserThreadLocal {

    private static final ThreadLocal userThreadLocal = new ThreadLocal();

    /**
     * 从当前线程获取UserInfo
     * */
    public static UserInfo getUserInfo(){
        return (UserInfo)userThreadLocal.get();
    }

    /**
     * 向当前线程保存UserInfo
     * */
    public static void setUserInfo(UserInfo userInfo){
        userThreadLocal.set(userInfo);
    }

    /**
     * 从当前线程删除UserInfo
     * */
    public static void removeUserInfo(){
        userThreadLocal.remove();
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class UserInfo{
        private Integer id;
        private String name;
    }

}
